package javamusic.DAO;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javamusic.excepcion.DAOExcepcion;
import javamusic.modelo.Persona;
import javamusic.util.ConexionBDKaraoke;



public class PersonaDAO extends BaseDAO {
	public Persona insertar(Persona vo) throws DAOExcepcion {
		String query = "insert into persona(dni,nombres,paterno,materno) values (?,?,?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			con = ConexionBDKaraoke.obtenerConexion();
			
			stmt = con.prepareStatement(query);
			stmt.setInt(1, vo.getDni());
			stmt.setString(2, vo.getNombre());
			stmt.setString(3, vo.getPaterno());
			stmt.setString(4, vo.getMaterno());
			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
			// Obtener el ultimo id
		

		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarResultSet(rs);
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
		return vo;
	}
	
	
	

}
